package 栈的弹出压入序列;

import java.util.Stack;

public class Solution {
    public boolean isPopOrder(int[] pushA, int[] popA) {
        Stack<Integer> stack = new Stack<>();
        int j = 0;  // 当时写的时候，由于 j 位置写错了。每次循环后，j都重新从0开始错误
        for (int i = 0; i < pushA.length; i++) {
            stack.push(pushA[i]);
//            int j = 0;   错误
            while (j < popA.length && !stack.empty() && stack.peek().equals(popA[j])) {
                stack.pop();
                j++;
            }
        }
        if (stack.empty()) {
            return true;
        }
        return false;
    }
}
